package com.glasses.business.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glasses.business.R;
import com.glasses.business.base.MyBaseAdapter;
import com.glasses.business.entity.CheckAttr;
import com.glasses.business.entity.User;
import com.glasses.business.inter.OnItemClick;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Author：邓勇军
 * English Name：Deng,The Sky Fucker!
 * Email：dandycoder@126.com
 * Date：2017/3/6
 * Version：1.0
 */

public class LightPopAdapter extends MyBaseAdapter<CheckAttr, LightPopAdapter.ViewHolder> {

    public LightPopAdapter(Activity context, List data) {
        super(context, data);
    }

    @Override
    protected ViewHolder getViewHolder() {
        return new ViewHolder(mInflater.inflate(R.layout.item_light_pop, null));
    }

    @Override
    protected void onBindViewHolder_(final ViewHolder holder, int position) {
        if (data != null && data.size() > 0) {
            final CheckAttr checkAttr = data.get(position);
            holder.typeName.setText(checkAttr.getName());
            if (checkAttr.isSelect()) {
                holder.typeName.setTextColor(context.getResources().getColor(R.color.red));
            } else {
                holder.typeName.setTextColor(context.getResources().getColor(R.color.text_black));
            }
            holder.typeLL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    for (int i = 0; i < data.size(); i++) {
                        data.get(i).setSelect(false);
                    }
                    checkAttr.setSelect(!checkAttr.isSelect());
                    if (checkAttr.isSelect()) {
                        holder.typeName.setTextColor(context.getResources().getColor(R.color.red));
                    } else {
                        holder.typeName.setTextColor(context.getResources().getColor(R.color.text_black));
                    }
                    onItemClick.onItemClick(0,checkAttr);
                }
            });
        }
    }

    private OnItemClick onItemClick;

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.typeLL)
        LinearLayout typeLL;
        @InjectView(R.id.typeName)
        TextView typeName;

        ViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
}
